<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
</head>
<body>
<!-- 导航条 -->
<nav class="navbar navbar-expand-lg bg-body-tertiary">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">Navbar</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="#">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">链接</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        下拉菜单
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="#">操作一</a></li>
                        <li><a class="dropdown-item" href="#">操作二</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="#">其他操作</a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    <a class="nav-link disabled" tabindex="-1" aria-disabled="true">禁用</a>
                </li>
            </ul>
        </div>
    </div>
</nav>
<!-- \导航条 -->

<!-- 登录表单 -->
<div class="container mt-5">
    <div class="row justify-content-center">
        <div class="col-md-6 col-lg-4">
            <div class="card">
                <div class="card-body">
                    <h5 class="card-title text-center mb-4">登录</h5>
                    <form>
                        <div class="mb-3">
                            <label for="exampleInputEmail1" class="form-label">邮箱地址</label>
                            <input type="email" class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
                            <div id="emailHelp" class="form-text">我们不会与他人共享您的邮箱。</div>
                        </div>
                        <div class="mb-3">
                            <label for="exampleInputPassword1" class="form-label">密码</label>
                            <input type="password" class="form-control" id="exampleInputPassword1">
                        </div>
                        <div class="mb-3 form-check">
                            <input type="checkbox" class="form-check-input" id="exampleCheck1">
                            <label class="form-check-label" for="exampleCheck1">记住我</label>
                        </div>
                        <button type="button" id="loginBtn" class="btn btn-primary d-block w-100">登录</button>
                        <a class="btn btn-primary d-block w-100 mt-3" href="regist.html">注册新账户</a>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- \登录表单 -->

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
    //fetch异步形式提交
    let loginBtn=  document.querySelector("#loginBtn");//拿到登录按钮
    let emailInput=document.querySelector("#exampleInputEmail1");
    let pwdInput= document.querySelector("#exampleInputPassword1");

    //绑定一个单击事件
    loginBtn.addEventListener('click',()=>{
        let data={email:emailInput.value,pwd:pwdInput.value};
        fetch("login", {
            method: "POST",
            headers: {
                "Content-Type": "application/json",
            },
            body: JSON.stringify(data),
        }).then(response=>response.json()).then((data)=>{
            if(data.flag){
                location.href="primary.html";
            }
        });
    });
</script>
</body>
</html>